package com.ooqiu.gaming.ui.preview;

import android.content.Context;
import android.support.v7.widget.Toolbar;
import android.text.ClipboardManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.ooqiu.gaming.R;
import com.ooqiu.gaming.base.BaseActivity;
import com.ooqiu.gaming.ui.web.WebActivity;
import com.ooqiu.gaming.view.Topbar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

@Route(path = QRCodePreviewActivity.PATH)
public class QRCodePreviewActivity extends BaseActivity {
    public static final String PATH = "/gn/qrcode_preview";

    @Autowired(name = "decode_res")
    String decodeStr;
    @BindView(R.id.topbar)
    Topbar mTopbar;
    @BindView(R.id.tv_decode_res)
    TextView mTvDecodeRes;
    @BindView(R.id.btn_gotoweb)
    Button mBtnGotoweb;
    @BindView(R.id.btn_copy)
    Button mBtnCopy;

    @Override
    public int initContentView() {
        return R.layout.activity_qrcode_preview;
    }

    @Override
    public void initInjector() {
        getRouter().inject(this);
        ButterKnife.bind(this);
    }

    @Override
    public void initUiAndListener() {
        mTvDecodeRes.setText(decodeStr);
    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isApplyStatusBarColor() {
        return true;
    }

    @Override
    protected Toolbar toolbarIdRes() {
        return null;
    }

    @Override
    protected View statusLayoutId() {
        return null;
    }


    @OnClick({R.id.btn_gotoweb, R.id.btn_copy})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_gotoweb:
                if (decodeStr.startsWith("http") || decodeStr.startsWith("http")) {
                    WebActivity.start(decodeStr);
                    finish();
                } else {
                    Toast.makeText(mContext, "网址非法", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.btn_copy:
                ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                // 将文本内容放到系统剪贴板里。
                cm.setText(decodeStr);
                Toast.makeText(mContext, "复制成功", Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
